using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace kattspel
{
    class Wizard : Sprite
    {
        Vector2 mStartingPosition = Vector2.Zero;
        const string WIZARD_ASSETNAME = "catrun";
        const int START_POSITION_X = 0;
        const int START_POSITION_Y = 450;
        const int WIZARD_SPEED = 160;
        const int MOVE_UP = -1;
        const int MOVE_DOWN = 1;
        const int MOVE_LEFT = 0;
        const int MOVE_RIGHT = 0;

        enum State
        {
            Walking,
            Jumping
        }
        State mCurrentState = State.Walking;

        Vector2 mDirection = Vector2.Zero;
        Vector2 mSpeed = Vector2.Zero;

        KeyboardState mPreviousKeyboardState;

        public void LoadContent(ContentManager theContentManager)
        {
            Position = new Vector2(START_POSITION_X, START_POSITION_Y);
            base.LoadContent(theContentManager, WIZARD_ASSETNAME);
        }

        public void Update(GameTime theGameTime)
        {
            KeyboardState aCurrentKeyboardState = Keyboard.GetState();

            
            UpdateJump(aCurrentKeyboardState);

            mPreviousKeyboardState = aCurrentKeyboardState;

            base.Update(theGameTime, mSpeed, mDirection);
        }

         private void UpdateJump(KeyboardState aCurrentKeyboardState) 
         {if (mCurrentState == State.Walking)
         {
        if (aCurrentKeyboardState.IsKeyDown(Keys.Space) == true
        && mPreviousKeyboardState.IsKeyDown(Keys.Space) == false)
        {Jump();}}
        if (mCurrentState == State.Jumping) 
        {if (mStartingPosition.Y - Position.Y > 150)
        {mDirection.Y = MOVE_DOWN;}if (Position.Y > mStartingPosition.Y)
        {Position.Y = mStartingPosition.Y;mCurrentState = State.Walking;
        mDirection = Vector2.Zero;} }}


         private void Jump() { if (mCurrentState != State.Jumping) 
        { mCurrentState = State.Jumping; mStartingPosition = Position; mDirection.Y = MOVE_UP; 
        mSpeed = new Vector2(WIZARD_SPEED, WIZARD_SPEED); } }
    }
}
